#include<iostream>
#include<vector>
using namespace std;

//快乐数

int number(int n)
{
    int sum = 0;
    while (n)
    {
        int m = n % 10;
        n /= 10;
        sum += m * m;
    }

    return sum;
}
bool isHappy(int n)
{
    int slow = n;
    int fast = number(n);
    while (slow != fast)
    {
        slow = number(slow);
        fast = number(number(fast));
    }

    return slow == 1;
}

int main(){
    int n=0;
    cin >> n;
    bool ret = isHappy(n);
    cout << ret << endl;
    return 0;
}